const randomNum = function randomNum(minNum, maxNum) {
  switch (arguments.length) {
    case 1:
      return parseInt(Math.random() * minNum + 1, 10);
    case 2:
      return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
    default:
      return 0;
  }
};

const requireJS = (url) => {
  return new Promise((resolve, reject) => {
    var script = document.createElement('script');
    script.type = "text/javascript";
    if (script.readyState) {
      script.onreadystatechange = function () {
        if (script.readyState == "loaded" || script.readyState == "complete") {
          script.onreadystatechange = null;
          resolve();
        }
      }
    } else {
      script.onload = function () {
        resolve();
      }
    }
    script.src = url;
    document.body.appendChild(script);
  });

};

module.exports = {
  randomNum,
  requireJS
};